#!/bin/bash

echo "Content-Type:text/html;charset=utf-8"
echo
#加载功能模块
source func/env.sh

source func/loginCheck.sh
source func/tools.sh
source func/db.sh

#写日志
log INFO "请求信息"
query_string=$(tee)

#传入动作
action=$(get_key action)
if [ $REQUEST_METHOD = "POST" ]; then
    action=$(echo $QUERY_STRING | sed 's/&/\n/g' | grep -w "action" | awk -F '=' '{print $2}')
fi

case $action in
login)
    checkLogin password
    ;;
register)
    View=$(cat template/register.html)
    eval "cat <<EOF
$(<template/base-login.html)
EOF"
    ;;
logout)
    echo "注销"

    eval "cat <<EOF
    $(<template/base.html)
EOF"
    echo "<script>\$.removeCookie('token');</script>"

    echo "<script>window.location.href=\"index.cgi\"</script>"

    ;;
*)

    echo "传入登录方法$action"

    ;;

esac
